package org.zfes.snowier.cloud.zbss.metting.router.service.pub;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.zfes.snowier.web.controller.BaseController;

import com.beust.jcommander.internal.Maps;

import org.zfes.snowier.cloud.zbss.metting.biz.model.MetCmsContent;
import org.zfes.snowier.cloud.zbss.metting.biz.service.IMetCmsContentService;
import org.zfes.snowier.core.data.DataSet;
import org.zfes.snowier.core.util.ZObjectUtil;
import org.zfes.snowier.core.util.ZStrUtil;
@Controller("org.zfes.snowier.cloud.zbss.metting.router.service.pub.MetCmsContentController") 
@RequestMapping("/met/service/pub/metCmsContent")
public class MetCmsContentController extends BaseController {

	
	@Autowired
	private IMetCmsContentService metCmsContentService;
	
	
    @RequestMapping(value="/loadMetCmsContentDataSet", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public  @ResponseBody Object loadMetCmsContentDataSet(@RequestParam Map<String,Object> params){
    	DataSet dataSet=metCmsContentService.loadMetCmsContentDataSet(params);
    	return ajaxDataSet(dataSet);
    }
    @RequestMapping(value="/loadMetCmsContent", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public  @ResponseBody Object loadMetCmsContent(Long id){
    	 Optional<MetCmsContent> metCmsContent=metCmsContentService.loadMetCmsContentById(id);
    	return ajaxQuery("metCmsContent", metCmsContent);
    }
    
    
    @RequestMapping(value="/loadMetCmsContentByIds", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public  @ResponseBody Object loadMetCmsContentByIds(String ids){
    	 List<MetCmsContent> contentList=metCmsContentService.loadMetCmsContentByIds(ZStrUtil.splitLong(ids));
    	 if(!ZObjectUtil.isEmpty(contentList)){
    		Map<String,MetCmsContent> maps= contentList.stream().collect(Collectors.toMap(con -> con.getId().toString(),con->con ));
    		return ajaxQuery("metCmsContentMap", maps);
    	 }
    	 
    	return ajaxQuery("metCmsContentMap", Maps.newHashMap());
    }

}